package oop.controller.action.question;

import oop.controller.action.DefaultAction;
import oop.db.dao.AnswerDAO;
import oop.db.dao.QuestionAnswerDAO;

public class DeleteAnswerAction extends DefaultAction {

	@Override
	public void performImpl() throws Exception {
		try {
			long questionId = Long.parseLong(request.getParameter("ad_question"));
			long answerId = Long.parseLong(request.getParameter("ad_answer"));
			QuestionAnswerDAO.removeAnswer(questionId, answerId);
			AnswerDAO.drop(answerId);
			setNextAction("question.view&qv_id=" + questionId);
		} catch (NumberFormatException ex) {
			request.setAttribute("message", "ID khong hop le");
			setNextAction("error");
		}
	}

}
